const Koa = require('koa')
const logger = require('koa-logger')
const KoaBodyParser = require('koa-bodyparser')
const cors = require('@koa/cors')
const Router = require('@koa/router')

const port = 3000

function applyCors(app) {
  app.use(cors())
}

function applyBodyParse(app) {
  app.use(KoaBodyParser())
}

// 加载路由中间件
function createApp() {
  const app = new Koa()
  applyBodyParse(app)
  applyCors(app)
  app.use(logger)
  app.listen(port, () => {
    console.log(`listening at http://localhost:${port}`)
  })
}

createApp()
